package com.kaiqingsun.io.OJ;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Scanner;

public class Main {
    private static Solution solution = new Solution();

    public static void main(String[] args) throws Exception {
        File inputFile = new File("D:\\比特\\网络原理\\OJ\\input.txt");
        File resultFile = new File("D:\\比特\\网络原理\\OJ\\output.txt");

        try (InputStream input = new FileInputStream(inputFile)) {
            try (InputStream result = new FileInputStream(resultFile)) {
                try (Scanner inputScanner = new Scanner(input, "UTF-8")) {
                    try (Scanner resultScanner = new Scanner(result, "UTF-8")) {
                        while (inputScanner.hasNextLine()) {
                            String line = inputScanner.nextLine();
                            String resultLine = resultScanner.nextLine();

                            test(line, resultLine);
                        }
                    }
                }
            }
        }
        System.out.println("测试用力全部通过");
    }

    private static void test(String inputLine, String resultLine) {
        //从intputLine中构建链表（不断地用尾插构建）
        ListNode head = new ListNode(-1);
        ListNode last = head;

        String[] array = inputLine.split(" ");
        for (String s : array) {
            int val = Integer.parseInt(s);//吧String变成int
            ListNode node = new ListNode(val);
            last.next = node;
            last = node;
        }
        ListNode reverseHead = solution.reverseList(head.next);
        //d对比reserveHead 构造的链表和resultLine 是否一致
        StringBuilder sb = new StringBuilder();
        for (ListNode cur = reverseHead; cur != null; cur = cur.next) {
            sb.append(cur.val).append(" ");
        }
        String acutalLine = null;
        if (sb.length() > 0) {
            sb.delete(sb.length() - 1, sb.length());
            acutalLine = sb.toString();
        }
        if (!acutalLine.equals(resultLine)) {
            System.out.println("输入" + inputLine);
            System.out.println("期望输出" + resultLine);
            System.out.println("实际输出" + acutalLine);
            System.exit(1);
        }
//    } catch (Exception exc) {
//        System.out.println("输入"+inputLine);
//        System.out.println("期望输出"+resultLine);
//        System.out.println("实际输出");
//        throw new RuntimeException(exc);
//    }

    }
}
